package solutions.ferpa.ztest.intf;

import br.com.telescope.adsrt.dom.DomDouble;
import br.com.telescope.adsrt.dom.DomId;
import br.com.telescope.adsrt.dom.DomInteger;
import br.com.telescope.adsrt.dom.DomText;
import br.com.telescope.adsrt.dom.DomTextLong;
import br.com.telescope.adsrt.dom.DomUpper;
import br.com.telescope.adsrt.lib.AdsException;
import br.com.telescope.adsrt.lib.Form;
import br.com.telescope.sql.ModelQuery;
import br.com.telescope.t2.EntityBinding;
import br.com.telescope.t2.ModuleNavigator;
import br.com.telescope.t2.ServiceModel;
import br.com.telescope.t2.feature.DeleteFeature;
import br.com.telescope.t2.feature.InsertFeature;
import br.com.telescope.t2.feature.ListFeature;
import br.com.telescope.t2.feature.LookupFeature;
import br.com.telescope.t2.feature.QueryFeature;
import br.com.telescope.t2.feature.UpdateFeature;
import br.com.telescope.t2.feature.ViewFeature;
import br.com.telescope.util.ObjectUtil;
import solutions.ferpa.ztest.ent.*;

/**
 * Cadastro de hidrômetros.
 * <p>
 * Interface para manutenção de Modelo de hidrômetro.
 * <P>
 * Telescope origin: ZTEST.CAD_MODELO_HIDROMETRO
 * <P>
 * Base entity: ZTEST.MODELO_HIDROMETRO
 * <P>
 * @author TELESCOPE - Build task T2 Web Interface Generator
 * <P>
 * @version 0.1
 */
public class CadModeloHidrometro extends ServiceModel {
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    public static final String GLOBAL_NAME = "ZTEST.CAD_MODELO_HIDROMETRO";
    
    @Override
    public String globalName() {
        return GLOBAL_NAME;
    }
    
    {
        setTitle("Cadastro de hidrômetros");
    }
    
    protected EntModeloHidrometro base;
    protected EntClasseModelo clmh;
    protected EntClasseModelo clmv;
    protected EntClasseModelo rzmh;
    protected EntClasseModelo rzmv;
    protected EntVazaoPrefixoSerie vpfs;
    protected EntVazaoPrefixoSerie vpmn;
    protected EntModeloHidrometro rec; // NEED_TJW1_COMPATIBILITY
    
    // Record items
    private DomUpper aCodigo;
    private DomText aDescricao;
    private DomInteger aDiametroNominal;
    private DomInteger aComprimento;
    private DomDouble aFatorK;
    private DomText aPortariaAprovacao;
    private DomUpper aMarca;
    private DomTextLong aDescricaoDetalhada;
    private DomId aId;
    private DomId aClasseHorizontalId;
    private DomId aClasseVerticalId;
    private DomId aVazaoPrefixoSerieId;
    private DomId aRazaoHorizontalId;
    private DomId aRazaoVerticalId;
    private DomId aVazaoPermanenteId;
    private DomUpper aClmhCodigo;
    private DomUpper aClmvCodigo;
    private DomUpper aRzmhCodigo;
    private DomUpper aRzmvCodigo;
    private DomDouble aVpfsVazaoNominal;
    private DomUpper aVpfsPrefixoNumeroSerie;
    private DomDouble aVpmnVazaoNominal;
    private DomUpper aVpmnPrefixoNumeroSerie;
    
    // Query items
    private DomUpper qVpmnPrefixoNumeroSerie;
    private DomInteger qDiametroNominal;
    private DomUpper qCodigo;
    private DomDouble qVpmnVazaoNominal;
    private DomUpper qMarca;
    private DomDouble qVpfsVazaoNominal;
    private DomUpper qClmvCodigo;
    private DomInteger qComprimento;
    private DomDouble qFatorK;
    private DomUpper qRzmvCodigo;
    private DomUpper qVpfsPrefixoNumeroSerie;
    private DomUpper qClmhCodigo;
    private DomUpper qRzmhCodigo;
    
    @Override
    public String getBaseSql() {
        return "select BASE.*"
                + " , CLMH.CODIGO as CLMH_CODIGO"
                + " , CLMV.CODIGO as CLMV_CODIGO"
                + " , RZMH.CODIGO as RZMH_CODIGO"
                + " , RZMV.CODIGO as RZMV_CODIGO"
                + " , VPFS.VAZAO_NOMINAL as VPFS_VAZAO_NOMINAL"
                + " , VPFS.PREFIXO_NUMERO_SERIE as VPFS_PREFIXO_NUMERO_SERIE"
                + " , VPMN.VAZAO_NOMINAL as VPMN_VAZAO_NOMINAL"
                + " , VPMN.PREFIXO_NUMERO_SERIE as VPMN_PREFIXO_NUMERO_SERIE"
                + " , CLMH.ID as Z_CLMH_ID"
                + " , CLMV.ID as Z_CLMV_ID"
                + " , RZMH.ID as Z_RZMH_ID"
                + " , RZMV.ID as Z_RZMV_ID"
                + " , VPFS.ID as Z_VPFS_ID"
                + " , VPMN.ID as Z_VPMN_ID"
                + " from MODELO_HIDROMETRO BASE"
                + " join CLASSE_MODELO CLMH on CLMH.ID = BASE.CLASSE_HORIZONTAL_ID"
                + " left join CLASSE_MODELO CLMV on CLMV.ID = BASE.CLASSE_VERTICAL_ID"
                + " left join CLASSE_MODELO RZMH on RZMH.ID = BASE.RAZAO_HORIZONTAL_ID"
                + " left join CLASSE_MODELO RZMV on RZMV.ID = BASE.RAZAO_VERTICAL_ID"
                + " join VAZAO_PREFIXO_SERIE VPFS on VPFS.ID = BASE.VAZAO_PREFIXO_SERIE_ID"
                + " join VAZAO_PREFIXO_SERIE VPMN on VPMN.ID = BASE.VAZAO_PERMANENTE_ID";
    }
    
    @Override
    public void initAttributes() {
        
        aCodigo = new DomUpper();
        aCodigo.context(ctx).name("CODIGO").label("Código do modelo de hidrômetro");
        
        aDescricao = new DomText();
        aDescricao.context(ctx).name("DESCRICAO").label("Descrição do hidrômetro");
        
        aDiametroNominal = new DomInteger();
        aDiametroNominal.context(ctx).name("DIAMETRO_NOMINAL").label("Diâmetro nominal (mm)");
        
        aComprimento = new DomInteger();
        aComprimento.context(ctx).name("COMPRIMENTO").label("Comprimento (mm)");
        
        aFatorK = new DomDouble();
        aFatorK.context(ctx).name("FATOR_K").label("Fator K");
        
        aPortariaAprovacao = new DomText();
        aPortariaAprovacao.context(ctx).name("PORTARIA_APROVACAO").label("Portaria de aprovação");
        
        aMarca = new DomUpper();
        aMarca.context(ctx).name("MARCA").label("Marca");
        aMarca.setDefaultValue("ZENNER");
        
        aDescricaoDetalhada = new DomTextLong();
        aDescricaoDetalhada.context(ctx).name("DESCRICAO_DETALHADA").label("Descrição detalhada do modelo");
        
        aId = new DomId();
        aId.context(ctx).name("ID").label("Id");
        
        aClasseHorizontalId = new DomId();
        aClasseHorizontalId.context(ctx).name("CLASSE_HORIZONTAL_ID").label("Classe metrológica na horizontal");
        
        aClasseVerticalId = new DomId();
        aClasseVerticalId.context(ctx).name("CLASSE_VERTICAL_ID").label("Classe metrológica na vertical");
        
        aVazaoPrefixoSerieId = new DomId();
        aVazaoPrefixoSerieId.context(ctx).name("VAZAO_PREFIXO_SERIE_ID").label("Vazão do hidrômetro");
        
        aRazaoHorizontalId = new DomId();
        aRazaoHorizontalId.context(ctx).name("RAZAO_HORIZONTAL_ID").label("Razão da vazão horizontal");
        
        aRazaoVerticalId = new DomId();
        aRazaoVerticalId.context(ctx).name("RAZAO_VERTICAL_ID").label("Razão da vazão vertical");
        
        aVazaoPermanenteId = new DomId();
        aVazaoPermanenteId.context(ctx).name("VAZAO_PERMANENTE_ID").label("Vazão permanente");
        
        aClmhCodigo = new DomUpper();
        aClmhCodigo.context(ctx).name("CLMH_CODIGO").label("Classe metrológica na horizontal");
        aClmhCodigo.setListOfValuesQuery(createQuery()
                .select("*")
                .from("(SELECT CODIGO as valor"
                + " , CODIGO as pesquisar"
                + " , CODIGO as descricao"
                + " from CLASSE_MODELO CLMH)", "q"));
        aClmhCodigo.setAutocompleteLength(0);
        
        aClmvCodigo = new DomUpper();
        aClmvCodigo.context(ctx).name("CLMV_CODIGO").label("Classe metrológica na vertical");
        aClmvCodigo.setListOfValuesQuery(createQuery()
                .select("*")
                .from("(SELECT CODIGO as valor"
                + " , CODIGO as pesquisar"
                + " , CODIGO as descricao"
                + " from CLASSE_MODELO CLMV)", "q"));
        aClmvCodigo.setAutocompleteLength(0);
        
        aRzmhCodigo = new DomUpper();
        aRzmhCodigo.context(ctx).name("RZMH_CODIGO").label("Razão horizontal");
        aRzmhCodigo.setListOfValuesQuery(createQuery()
                .select("*")
                .from("(SELECT CODIGO as valor"
                + " , CODIGO as pesquisar"
                + " , CODIGO as descricao"
                + " from CLASSE_MODELO RZMH)", "q"));
        aRzmhCodigo.setAutocompleteLength(0);
        
        aRzmvCodigo = new DomUpper();
        aRzmvCodigo.context(ctx).name("RZMV_CODIGO").label("Razão vertical");
        aRzmvCodigo.setListOfValuesQuery(createQuery()
                .select("*")
                .from("(SELECT CODIGO as valor"
                + " , CODIGO as pesquisar"
                + " , CODIGO as descricao"
                + " from CLASSE_MODELO RZMV)", "q"));
        aRzmvCodigo.setAutocompleteLength(0);
        
        aVpfsVazaoNominal = new DomDouble();
        aVpfsVazaoNominal.context(ctx).name("VPFS_VAZAO_NOMINAL").label("Vazão nominal (m3/h)");
        aVpfsVazaoNominal.setListOfValuesQuery(createQuery()
                .select("*")
                .from("(SELECT VAZAO_NOMINAL as valor"
                + " , VAZAO_NOMINAL as pesquisar"
                + " , VAZAO_NOMINAL as descricao"
                + " from VAZAO_PREFIXO_SERIE VPFS)", "q"));
        aVpfsVazaoNominal.setAutocompleteLength(0);
        
        aVpfsPrefixoNumeroSerie = new DomUpper();
        aVpfsPrefixoNumeroSerie.context(ctx).name("VPFS_PREFIXO_NUMERO_SERIE").label("Prefixo para número de série");
        aVpfsPrefixoNumeroSerie.setListOfValuesQuery(createQuery()
                .select("*")
                .from("(SELECT PREFIXO_NUMERO_SERIE as valor"
                + " , PREFIXO_NUMERO_SERIE as pesquisar"
                + " , PREFIXO_NUMERO_SERIE as descricao"
                + " from VAZAO_PREFIXO_SERIE VPFS)", "q"));
        aVpfsPrefixoNumeroSerie.setAutocompleteLength(0);
        
        aVpmnVazaoNominal = new DomDouble();
        aVpmnVazaoNominal.context(ctx).name("VPMN_VAZAO_NOMINAL").label("Vazão permante");
        aVpmnVazaoNominal.setListOfValuesQuery(createQuery()
                .select("*")
                .from("(SELECT VAZAO_NOMINAL as valor"
                + " , VAZAO_NOMINAL as pesquisar"
                + " , VAZAO_NOMINAL as descricao"
                + " from VAZAO_PREFIXO_SERIE VPMN)", "q"));
        aVpmnVazaoNominal.setAutocompleteLength(0);
        
        aVpmnPrefixoNumeroSerie = new DomUpper();
        aVpmnPrefixoNumeroSerie.context(ctx).name("VPMN_PREFIXO_NUMERO_SERIE").label("Prefixo da vazão permanente");
        aVpmnPrefixoNumeroSerie.setListOfValuesQuery(createQuery()
                .select("*")
                .from("(SELECT PREFIXO_NUMERO_SERIE as valor"
                + " , PREFIXO_NUMERO_SERIE as pesquisar"
                + " , PREFIXO_NUMERO_SERIE as descricao"
                + " from VAZAO_PREFIXO_SERIE VPMN)", "q"));
        aVpmnPrefixoNumeroSerie.setAutocompleteLength(0);
        
        
        qVpmnPrefixoNumeroSerie = new DomUpper();
        qVpmnPrefixoNumeroSerie.context(ctx).name("VPMN_PREFIXO_NUMERO_SERIE").label("Prefixo da vazão permanente");
        qVpmnPrefixoNumeroSerie.setListOfValuesQuery(createQuery()
                .select("*")
                .from("(SELECT PREFIXO_NUMERO_SERIE as valor"
                + " , PREFIXO_NUMERO_SERIE as pesquisar"
                + " , PREFIXO_NUMERO_SERIE as descricao"
                + " from VAZAO_PREFIXO_SERIE VPMN)", "q"));
        qVpmnPrefixoNumeroSerie.setAutocompleteLength(0);
        
        qDiametroNominal = new DomInteger();
        qDiametroNominal.context(ctx).name("DIAMETRO_NOMINAL").label("Diâmetro nominal (mm)");
        
        qCodigo = new DomUpper();
        qCodigo.context(ctx).name("CODIGO").label("Código do modelo de hidrômetro");
        
        qVpmnVazaoNominal = new DomDouble();
        qVpmnVazaoNominal.context(ctx).name("VPMN_VAZAO_NOMINAL").label("Vazão permante");
        qVpmnVazaoNominal.setListOfValuesQuery(createQuery()
                .select("*")
                .from("(SELECT VAZAO_NOMINAL as valor"
                + " , VAZAO_NOMINAL as pesquisar"
                + " , VAZAO_NOMINAL as descricao"
                + " from VAZAO_PREFIXO_SERIE VPMN)", "q"));
        qVpmnVazaoNominal.setAutocompleteLength(0);
        
        qMarca = new DomUpper();
        qMarca.context(ctx).name("MARCA").label("Marca");
        
        qVpfsVazaoNominal = new DomDouble();
        qVpfsVazaoNominal.context(ctx).name("VPFS_VAZAO_NOMINAL").label("Vazão nominal (m3/h)");
        qVpfsVazaoNominal.setListOfValuesQuery(createQuery()
                .select("*")
                .from("(SELECT VAZAO_NOMINAL as valor"
                + " , VAZAO_NOMINAL as pesquisar"
                + " , VAZAO_NOMINAL as descricao"
                + " from VAZAO_PREFIXO_SERIE VPFS)", "q"));
        qVpfsVazaoNominal.setAutocompleteLength(0);
        
        qClmvCodigo = new DomUpper();
        qClmvCodigo.context(ctx).name("CLMV_CODIGO").label("Classe metrológica na vertical");
        qClmvCodigo.setListOfValuesQuery(createQuery()
                .select("*")
                .from("(SELECT CODIGO as valor"
                + " , CODIGO as pesquisar"
                + " , CODIGO as descricao"
                + " from CLASSE_MODELO CLMV)", "q"));
        qClmvCodigo.setAutocompleteLength(0);
        
        qComprimento = new DomInteger();
        qComprimento.context(ctx).name("COMPRIMENTO").label("Comprimento (mm)");
        
        qFatorK = new DomDouble();
        qFatorK.context(ctx).name("FATOR_K").label("Fator K");
        
        qRzmvCodigo = new DomUpper();
        qRzmvCodigo.context(ctx).name("RZMV_CODIGO").label("Razão vertical");
        qRzmvCodigo.setListOfValuesQuery(createQuery()
                .select("*")
                .from("(SELECT CODIGO as valor"
                + " , CODIGO as pesquisar"
                + " , CODIGO as descricao"
                + " from CLASSE_MODELO RZMV)", "q"));
        qRzmvCodigo.setAutocompleteLength(0);
        
        qVpfsPrefixoNumeroSerie = new DomUpper();
        qVpfsPrefixoNumeroSerie.context(ctx).name("VPFS_PREFIXO_NUMERO_SERIE").label("Prefixo para número de série");
        qVpfsPrefixoNumeroSerie.setListOfValuesQuery(createQuery()
                .select("*")
                .from("(SELECT PREFIXO_NUMERO_SERIE as valor"
                + " , PREFIXO_NUMERO_SERIE as pesquisar"
                + " , PREFIXO_NUMERO_SERIE as descricao"
                + " from VAZAO_PREFIXO_SERIE VPFS)", "q"));
        qVpfsPrefixoNumeroSerie.setAutocompleteLength(0);
        
        qClmhCodigo = new DomUpper();
        qClmhCodigo.context(ctx).name("CLMH_CODIGO").label("Classe metrológica na horizontal");
        qClmhCodigo.setListOfValuesQuery(createQuery()
                .select("*")
                .from("(SELECT CODIGO as valor"
                + " , CODIGO as pesquisar"
                + " , CODIGO as descricao"
                + " from CLASSE_MODELO CLMH)", "q"));
        qClmhCodigo.setAutocompleteLength(0);
        
        qRzmhCodigo = new DomUpper();
        qRzmhCodigo.context(ctx).name("RZMH_CODIGO").label("Razão horizontal");
        qRzmhCodigo.setListOfValuesQuery(createQuery()
                .select("*")
                .from("(SELECT CODIGO as valor"
                + " , CODIGO as pesquisar"
                + " , CODIGO as descricao"
                + " from CLASSE_MODELO RZMH)", "q"));
        qRzmhCodigo.setAutocompleteLength(0);
    }
    
    @Override
    public void initEntityBindings() {
        EntityBinding binding;
        
        binding = new EntityBinding("ZTEST.CLASSE_MODELO", "CLMH", "Z_CLMH_ID", "ZTEST.CAD_CLASSE_MODELO.VIEW");
        binding.addFields(aClmhCodigo);
        entityBindings.add(binding);
        
        binding = new EntityBinding("ZTEST.CLASSE_MODELO", "CLMV", "Z_CLMV_ID", "ZTEST.CAD_CLASSE_MODELO.VIEW");
        binding.addFields(aClmvCodigo);
        entityBindings.add(binding);
        
        binding = new EntityBinding("ZTEST.CLASSE_MODELO", "RZMH", "Z_RZMH_ID", "ZTEST.CAD_CLASSE_MODELO.VIEW");
        binding.addFields(aRzmhCodigo);
        entityBindings.add(binding);
        
        binding = new EntityBinding("ZTEST.CLASSE_MODELO", "RZMV", "Z_RZMV_ID", "ZTEST.CAD_CLASSE_MODELO.VIEW");
        binding.addFields(aRzmvCodigo);
        entityBindings.add(binding);
    }
    
    @Override
    public String getQueryPkColumn() {
        return "BASE.ID";
    }
    
    @Override
    public void setId(String value) {
        this.aId.setValue(value);
    }
    
    @Override
    public EntModeloHidrometro getRecord() {
        if (base == null) {
            base = new EntModeloHidrometro(ctx);
            rec = base;
        }
        return this.base;
    }
    
    @Override
    public String getContextName() {
        return aCodigo.toText();
    }
    
    @Override
    public String getDefaultOrderBy() {
        return "CODIGO, VPFS_VAZAO_NOMINAL, VPFS_PREFIXO_NUMERO_SERIE, VPMN_VAZAO_NOMINAL";
    }
    
    @Override
    public void translateInsertFks(Form form) {
        ModelQuery query;
        
        // CLASSE_HORIZONTAL_ID
        try {
            if (form.hasFields("CLMH_CODIGO")) {
                query = createQuery()
                        .select("CLMH.ID")
                        .from("CLASSE_MODELO", "CLMH")
                        .filter("CLMH.CODIGO", form.get("CLMH_CODIGO"))
                        ;
                base.setClasseHorizontalId(ObjectUtil.toLong(translateFk(query)));
            }
        } catch (AdsException ex) {
            throw new RuntimeException(ex);
        }
        
        // CLASSE_VERTICAL_ID
        try {
            if (form.hasFields("CLMV_CODIGO")) {
                query = createQuery()
                        .select("CLMV.ID")
                        .from("CLASSE_MODELO", "CLMV")
                        .filter("CLMV.CODIGO", form.get("CLMV_CODIGO"))
                        ;
                base.setClasseVerticalId(ObjectUtil.toLong(translateFk(query)));
            }
        } catch (AdsException ex) {
            throw new RuntimeException(ex);
        }
        
        // RAZAO_HORIZONTAL_ID
        try {
            if (form.hasFields("RZMH_CODIGO")) {
                query = createQuery()
                        .select("RZMH.ID")
                        .from("CLASSE_MODELO", "RZMH")
                        .filter("RZMH.CODIGO", form.get("RZMH_CODIGO"))
                        ;
                base.setRazaoHorizontalId(ObjectUtil.toLong(translateFk(query)));
            }
        } catch (AdsException ex) {
            throw new RuntimeException(ex);
        }
        
        // RAZAO_VERTICAL_ID
        try {
            if (form.hasFields("RZMV_CODIGO")) {
                query = createQuery()
                        .select("RZMV.ID")
                        .from("CLASSE_MODELO", "RZMV")
                        .filter("RZMV.CODIGO", form.get("RZMV_CODIGO"))
                        ;
                base.setRazaoVerticalId(ObjectUtil.toLong(translateFk(query)));
            }
        } catch (AdsException ex) {
            throw new RuntimeException(ex);
        }
        
        // VAZAO_PREFIXO_SERIE_ID
        try {
            if (form.hasFields("VPFS_VAZAO_NOMINAL")) {
                query = createQuery()
                        .select("VPFS.ID")
                        .from("VAZAO_PREFIXO_SERIE", "VPFS")
                        .filter("VPFS.VAZAO_NOMINAL", form.get("VPFS_VAZAO_NOMINAL"))
                        ;
                base.setVazaoPrefixoSerieId(ObjectUtil.toLong(translateFk(query)));
            }
        } catch (AdsException ex) {
            throw new RuntimeException(ex);
        }
        
        // VAZAO_PERMANENTE_ID
        try {
            if (form.hasFields("VPMN_VAZAO_NOMINAL")) {
                query = createQuery()
                        .select("VPMN.ID")
                        .from("VAZAO_PREFIXO_SERIE", "VPMN")
                        .filter("VPMN.VAZAO_NOMINAL", form.get("VPMN_VAZAO_NOMINAL"))
                        ;
                base.setVazaoPermanenteId(ObjectUtil.toLong(translateFk(query)));
            }
        } catch (AdsException ex) {
            throw new RuntimeException(ex);
        }
    }
    
    @Override
    public void translateUpdateFks(Form form) {
        ModelQuery query;
        
        // CLASSE_HORIZONTAL_ID
        try {
            if (form.hasFields("CLMH_CODIGO")) {
                query = createQuery()
                        .select("CLMH.ID")
                        .from("CLASSE_MODELO", "CLMH")
                        .filter("CLMH.CODIGO", form.get("CLMH_CODIGO"))
                        ;
                base.setClasseHorizontalId(ObjectUtil.toLong(translateFk(query)));
            }
        } catch (AdsException ex) {
            throw new RuntimeException(ex);
        }
        
        // CLASSE_VERTICAL_ID
        try {
            if (form.hasFields("CLMV_CODIGO")) {
                query = createQuery()
                        .select("CLMV.ID")
                        .from("CLASSE_MODELO", "CLMV")
                        .filter("CLMV.CODIGO", form.get("CLMV_CODIGO"))
                        ;
                base.setClasseVerticalId(ObjectUtil.toLong(translateFk(query)));
            }
        } catch (AdsException ex) {
            throw new RuntimeException(ex);
        }
        
        // RAZAO_HORIZONTAL_ID
        try {
            if (form.hasFields("RZMH_CODIGO")) {
                query = createQuery()
                        .select("RZMH.ID")
                        .from("CLASSE_MODELO", "RZMH")
                        .filter("RZMH.CODIGO", form.get("RZMH_CODIGO"))
                        ;
                base.setRazaoHorizontalId(ObjectUtil.toLong(translateFk(query)));
            }
        } catch (AdsException ex) {
            throw new RuntimeException(ex);
        }
        
        // RAZAO_VERTICAL_ID
        try {
            if (form.hasFields("RZMV_CODIGO")) {
                query = createQuery()
                        .select("RZMV.ID")
                        .from("CLASSE_MODELO", "RZMV")
                        .filter("RZMV.CODIGO", form.get("RZMV_CODIGO"))
                        ;
                base.setRazaoVerticalId(ObjectUtil.toLong(translateFk(query)));
            }
        } catch (AdsException ex) {
            throw new RuntimeException(ex);
        }
        
        // VAZAO_PREFIXO_SERIE_ID
        try {
            if (form.hasFields("VPFS_VAZAO_NOMINAL")) {
                query = createQuery()
                        .select("VPFS.ID")
                        .from("VAZAO_PREFIXO_SERIE", "VPFS")
                        .filter("VPFS.VAZAO_NOMINAL", form.get("VPFS_VAZAO_NOMINAL"))
                        ;
                base.setVazaoPrefixoSerieId(ObjectUtil.toLong(translateFk(query)));
            }
        } catch (AdsException ex) {
            throw new RuntimeException(ex);
        }
        
        // VAZAO_PERMANENTE_ID
        try {
            if (form.hasFields("VPMN_VAZAO_NOMINAL")) {
                query = createQuery()
                        .select("VPMN.ID")
                        .from("VAZAO_PREFIXO_SERIE", "VPMN")
                        .filter("VPMN.VAZAO_NOMINAL", form.get("VPMN_VAZAO_NOMINAL"))
                        ;
                base.setVazaoPermanenteId(ObjectUtil.toLong(translateFk(query)));
            }
        } catch (AdsException ex) {
            throw new RuntimeException(ex);
        }
    }
    
    @Override
    public ModuleNavigator getDefaultModuleNavigator() {
        return new ModMdlhidr();
    }
    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="QUERY">
    public class FQuery extends QueryFeature {
        
        @Override
        public void initForm() {
            addField(qCodigo, "opt");
            addField(qVpfsVazaoNominal, "opt");
            addField(qVpfsPrefixoNumeroSerie, "opt");
            addField(qVpmnVazaoNominal, "opt");
            addField(qVpmnPrefixoNumeroSerie, "opt");
            addField(qDiametroNominal, "opt");
            addField(qComprimento, "opt");
            addField(qFatorK, "opt");
            addField(qClmhCodigo, "opt");
            addField(qClmvCodigo, "opt");
            addField(qRzmhCodigo, "opt");
            addField(qRzmvCodigo, "opt");
            addField(qMarca, "opt");
        }
        
        {
            setFeatureName("QUERY");
            setPrimary(false);
        }
    }
    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="LIST">
    public class FList extends ListFeature {
        
        @Override
        public void initForm() {
            addField(aCodigo, "view");
            addField(aVpfsVazaoNominal, "view");
            addField(aVpfsPrefixoNumeroSerie, "view");
            addField(aVpmnVazaoNominal, "view");
            addField(aVpmnPrefixoNumeroSerie, "view");
            addField(aDescricao, "view");
            addField(aDiametroNominal, "view");
            addField(aComprimento, "view");
            addField(aFatorK, "view");
            addField(aClmhCodigo, "view");
            addField(aClmvCodigo, "view");
            addField(aRzmhCodigo, "view");
            addField(aRzmvCodigo, "view");
        }
        
        {
            setFeatureName("LIST");
            setPrimary(false);
        }
    }
    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="VIEW">
    public class FView extends ViewFeature {
        
        @Override
        public void initForm() {
            addField(aCodigo, "view");
            addField(aVpfsVazaoNominal, "view");
            addField(aVpfsPrefixoNumeroSerie, "view");
            addField(aVpmnVazaoNominal, "view");
            addField(aVpmnPrefixoNumeroSerie, "view");
            addField(aDescricao, "view");
            addField(aDiametroNominal, "view");
            addField(aComprimento, "view");
            addField(aFatorK, "view");
            addField(aClmhCodigo, "view");
            addField(aClmvCodigo, "view");
            addField(aRzmhCodigo, "view");
            addField(aRzmvCodigo, "view");
            addField(aPortariaAprovacao, "view");
            addField(aMarca, "view");
            addField(aDescricaoDetalhada, "view");
        }
        
        {
            setFeatureName("VIEW");
            setPrimary(false);
        }
    }
    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="INSERT">
    public class FInsert extends InsertFeature {
        
        @Override
        public void initForm() {
            aCodigo.setOptional(false);
            addField(aCodigo, "rqd");
            addField(aVpfsVazaoNominal, "opt");
            aVpfsPrefixoNumeroSerie.setEditable(false);
            addField(aVpfsPrefixoNumeroSerie, "view");
            aVpmnVazaoNominal.setOptional(false);
            addField(aVpmnVazaoNominal, "rqd");
            aVpmnPrefixoNumeroSerie.setEditable(false);
            addField(aVpmnPrefixoNumeroSerie, "view");
            aDescricao.setOptional(false);
            addField(aDescricao, "rqd");
            aDiametroNominal.setOptional(false);
            addField(aDiametroNominal, "rqd");
            aComprimento.setOptional(false);
            addField(aComprimento, "rqd");
            addField(aFatorK, "opt");
            aClmhCodigo.setOptional(false);
            addField(aClmhCodigo, "rqd");
            addField(aClmvCodigo, "opt");
            addField(aRzmhCodigo, "opt");
            addField(aRzmvCodigo, "opt");
            aMarca.setEditable(false);
            addField(aMarca, "view");
            addField(aDescricaoDetalhada, "opt");
        }
        
        {
            setFeatureName("INSERT");
            setPrimary(false);
        }
    }
    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="UPDATE">
    public class FUpdate extends UpdateFeature {
        
        @Override
        public void initForm() {
            aCodigo.setOptional(false);
            addField(aCodigo, "rqd");
            aVpfsVazaoNominal.setOptional(false);
            addField(aVpfsVazaoNominal, "rqd");
            aVpfsPrefixoNumeroSerie.setEditable(false);
            addField(aVpfsPrefixoNumeroSerie, "view");
            aVpmnVazaoNominal.setOptional(false);
            addField(aVpmnVazaoNominal, "rqd");
            aVpmnPrefixoNumeroSerie.setEditable(false);
            addField(aVpmnPrefixoNumeroSerie, "view");
            aDescricao.setOptional(false);
            addField(aDescricao, "rqd");
            aDiametroNominal.setOptional(false);
            addField(aDiametroNominal, "rqd");
            aComprimento.setOptional(false);
            addField(aComprimento, "rqd");
            addField(aFatorK, "opt");
            aClmhCodigo.setOptional(false);
            addField(aClmhCodigo, "rqd");
            addField(aClmvCodigo, "opt");
            addField(aRzmhCodigo, "opt");
            addField(aRzmvCodigo, "opt");
            aPortariaAprovacao.setOptional(false);
            addField(aPortariaAprovacao, "rqd");
            aMarca.setOptional(false);
            addField(aMarca, "rqd");
            addField(aDescricaoDetalhada, "opt");
        }
        
        {
            setFeatureName("UPDATE");
            setPrimary(false);
        }
    }
    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="DELETE">
    public class FDelete extends DeleteFeature {
        
        @Override
        public void initForm() {
            addField(aCodigo, "view");
            addField(aVpfsVazaoNominal, "view");
            addField(aDescricao, "view");
            addField(aClmhCodigo, "view");
            addField(aClmvCodigo, "view");
            addField(aRzmhCodigo, "view");
            addField(aRzmvCodigo, "view");
        }
        
        {
            setFeatureName("DELETE");
            setPrimary(false);
        }
    }
    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="CLMH_CODIGO_LOOKUP">
    public class FClmhCodigoLookup extends LookupFeature {
        
        @Override
        public void initForm() {
            aClmhCodigo.setEditable(true);
            addField(aClmhCodigo, "opt");
        }
        
        @Override
        public ModelQuery getLookupQuery() {
            return createQuery()
                    .select("CLMH.CODIGO as CLMH_CODIGO")
                    .from("CLASSE_MODELO", "CLMH")
                    ;
        }
        
        {
            setFeatureName("CLMH_CODIGO_LOOKUP");
        }
    }
    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="CLMV_CODIGO_LOOKUP">
    public class FClmvCodigoLookup extends LookupFeature {
        
        @Override
        public void initForm() {
            aClmvCodigo.setEditable(true);
            addField(aClmvCodigo, "opt");
        }
        
        @Override
        public ModelQuery getLookupQuery() {
            return createQuery()
                    .select("CLMV.CODIGO as CLMV_CODIGO")
                    .from("CLASSE_MODELO", "CLMV")
                    ;
        }
        
        {
            setFeatureName("CLMV_CODIGO_LOOKUP");
        }
    }
    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="RZMH_CODIGO_LOOKUP">
    public class FRzmhCodigoLookup extends LookupFeature {
        
        @Override
        public void initForm() {
            aRzmhCodigo.setEditable(true);
            addField(aRzmhCodigo, "opt");
        }
        
        @Override
        public ModelQuery getLookupQuery() {
            return createQuery()
                    .select("RZMH.CODIGO as RZMH_CODIGO")
                    .from("CLASSE_MODELO", "RZMH")
                    ;
        }
        
        {
            setFeatureName("RZMH_CODIGO_LOOKUP");
        }
    }
    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="RZMV_CODIGO_LOOKUP">
    public class FRzmvCodigoLookup extends LookupFeature {
        
        @Override
        public void initForm() {
            aRzmvCodigo.setEditable(true);
            addField(aRzmvCodigo, "opt");
        }
        
        @Override
        public ModelQuery getLookupQuery() {
            return createQuery()
                    .select("RZMV.CODIGO as RZMV_CODIGO")
                    .from("CLASSE_MODELO", "RZMV")
                    ;
        }
        
        {
            setFeatureName("RZMV_CODIGO_LOOKUP");
        }
    }
    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="VPFS_VAZAO_NOMINAL_LOOKUP">
    public class FVpfsVazaoNominalLookup extends LookupFeature {
        
        @Override
        public void initForm() {
            aVpfsVazaoNominal.setEditable(true);
            addField(aVpfsVazaoNominal, "opt");
            aVpfsPrefixoNumeroSerie.setEditable(false);
            addField(aVpfsPrefixoNumeroSerie, "view");
        }
        
        @Override
        public ModelQuery getLookupQuery() {
            return createQuery()
                    .select("VPFS.VAZAO_NOMINAL as VPFS_VAZAO_NOMINAL")
                    .select("VPFS.PREFIXO_NUMERO_SERIE as VPFS_PREFIXO_NUMERO_SERIE")
                    .from("VAZAO_PREFIXO_SERIE", "VPFS")
                    ;
        }
        
        {
            setFeatureName("VPFS_VAZAO_NOMINAL_LOOKUP");
        }
    }
    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="VPMN_VAZAO_NOMINAL_LOOKUP">
    public class FVpmnVazaoNominalLookup extends LookupFeature {
        
        @Override
        public void initForm() {
            aVpmnVazaoNominal.setEditable(true);
            addField(aVpmnVazaoNominal, "opt");
            aVpmnPrefixoNumeroSerie.setEditable(false);
            addField(aVpmnPrefixoNumeroSerie, "view");
        }
        
        @Override
        public ModelQuery getLookupQuery() {
            return createQuery()
                    .select("VPMN.VAZAO_NOMINAL as VPMN_VAZAO_NOMINAL")
                    .select("VPMN.PREFIXO_NUMERO_SERIE as VPMN_PREFIXO_NUMERO_SERIE")
                    .from("VAZAO_PREFIXO_SERIE", "VPMN")
                    ;
        }
        
        {
            setFeatureName("VPMN_VAZAO_NOMINAL_LOOKUP");
        }
    }
    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="initFeatures">
    
    @Override
    protected void initFeatures() {
        addFeature(new FQuery());
        addFeature(new FList());
        addFeature(new FView());
        addFeature(new FInsert());
        addFeature(new FUpdate());
        addFeature(new FDelete());
        addFeature(new FClmhCodigoLookup());
        addFeature(new FClmvCodigoLookup());
        addFeature(new FRzmhCodigoLookup());
        addFeature(new FRzmvCodigoLookup());
        addFeature(new FVpfsVazaoNominalLookup());
        addFeature(new FVpmnVazaoNominalLookup());
        super.initFeatures();
    }
    
    @Override
    public String getDefaultFeature() {
        return "QUERY";
    }
    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="Getters and Setters">
    
    public String getCodigo() {
        return aCodigo.getValue();
    }
    
    public void setCodigo(String value) {
        this.aCodigo.setValue(value);
    }
    
    public String getDescricao() {
        return aDescricao.getValue();
    }
    
    public void setDescricao(String value) {
        this.aDescricao.setValue(value);
    }
    
    public Integer getDiametroNominal() {
        return aDiametroNominal.getValue();
    }
    
    public void setDiametroNominal(Integer value) {
        this.aDiametroNominal.setValue(value);
    }
    
    public Integer getComprimento() {
        return aComprimento.getValue();
    }
    
    public void setComprimento(Integer value) {
        this.aComprimento.setValue(value);
    }
    
    public Double getFatorK() {
        return aFatorK.getValue();
    }
    
    public void setFatorK(Double value) {
        this.aFatorK.setValue(value);
    }
    
    public String getPortariaAprovacao() {
        return aPortariaAprovacao.getValue();
    }
    
    public void setPortariaAprovacao(String value) {
        this.aPortariaAprovacao.setValue(value);
    }
    
    public String getMarca() {
        return aMarca.getValue();
    }
    
    public void setMarca(String value) {
        this.aMarca.setValue(value);
    }
    
    public String getDescricaoDetalhada() {
        return aDescricaoDetalhada.getValue();
    }
    
    public void setDescricaoDetalhada(String value) {
        this.aDescricaoDetalhada.setValue(value);
    }
    
    @Override
    public Long getId() {
        return aId.getValue();
    }
    
    public void setId(Long value) {
        this.aId.setValue(value);
    }
    
    public Long getClasseHorizontalId() {
        return aClasseHorizontalId.getValue();
    }
    
    public void setClasseHorizontalId(Long value) {
        this.aClasseHorizontalId.setValue(value);
    }
    
    public Long getClasseVerticalId() {
        return aClasseVerticalId.getValue();
    }
    
    public void setClasseVerticalId(Long value) {
        this.aClasseVerticalId.setValue(value);
    }
    
    public Long getVazaoPrefixoSerieId() {
        return aVazaoPrefixoSerieId.getValue();
    }
    
    public void setVazaoPrefixoSerieId(Long value) {
        this.aVazaoPrefixoSerieId.setValue(value);
    }
    
    public Long getRazaoHorizontalId() {
        return aRazaoHorizontalId.getValue();
    }
    
    public void setRazaoHorizontalId(Long value) {
        this.aRazaoHorizontalId.setValue(value);
    }
    
    public Long getRazaoVerticalId() {
        return aRazaoVerticalId.getValue();
    }
    
    public void setRazaoVerticalId(Long value) {
        this.aRazaoVerticalId.setValue(value);
    }
    
    public Long getVazaoPermanenteId() {
        return aVazaoPermanenteId.getValue();
    }
    
    public void setVazaoPermanenteId(Long value) {
        this.aVazaoPermanenteId.setValue(value);
    }
    
    public String getClmhCodigo() {
        return aClmhCodigo.getValue();
    }
    
    public void setClmhCodigo(String value) {
        this.aClmhCodigo.setValue(value);
    }
    
    public String getClmvCodigo() {
        return aClmvCodigo.getValue();
    }
    
    public void setClmvCodigo(String value) {
        this.aClmvCodigo.setValue(value);
    }
    
    public String getRzmhCodigo() {
        return aRzmhCodigo.getValue();
    }
    
    public void setRzmhCodigo(String value) {
        this.aRzmhCodigo.setValue(value);
    }
    
    public String getRzmvCodigo() {
        return aRzmvCodigo.getValue();
    }
    
    public void setRzmvCodigo(String value) {
        this.aRzmvCodigo.setValue(value);
    }
    
    public Double getVpfsVazaoNominal() {
        return aVpfsVazaoNominal.getValue();
    }
    
    public void setVpfsVazaoNominal(Double value) {
        this.aVpfsVazaoNominal.setValue(value);
    }
    
    public String getVpfsPrefixoNumeroSerie() {
        return aVpfsPrefixoNumeroSerie.getValue();
    }
    
    public void setVpfsPrefixoNumeroSerie(String value) {
        this.aVpfsPrefixoNumeroSerie.setValue(value);
    }
    
    public Double getVpmnVazaoNominal() {
        return aVpmnVazaoNominal.getValue();
    }
    
    public void setVpmnVazaoNominal(Double value) {
        this.aVpmnVazaoNominal.setValue(value);
    }
    
    public String getVpmnPrefixoNumeroSerie() {
        return aVpmnPrefixoNumeroSerie.getValue();
    }
    
    public void setVpmnPrefixoNumeroSerie(String value) {
        this.aVpmnPrefixoNumeroSerie.setValue(value);
    }
    public String getQueryCodigo() {
        return qCodigo.getQueryValue();
    }
    
    public void setQueryCodigo(String value) {
        this.qCodigo.setQueryValue(value);
    }
    public String getQueryVpfsVazaoNominal() {
        return qVpfsVazaoNominal.getQueryValue();
    }
    
    public void setQueryVpfsVazaoNominal(String value) {
        this.qVpfsVazaoNominal.setQueryValue(value);
    }
    public String getQueryVpfsPrefixoNumeroSerie() {
        return qVpfsPrefixoNumeroSerie.getQueryValue();
    }
    
    public void setQueryVpfsPrefixoNumeroSerie(String value) {
        this.qVpfsPrefixoNumeroSerie.setQueryValue(value);
    }
    public String getQueryVpmnVazaoNominal() {
        return qVpmnVazaoNominal.getQueryValue();
    }
    
    public void setQueryVpmnVazaoNominal(String value) {
        this.qVpmnVazaoNominal.setQueryValue(value);
    }
    public String getQueryVpmnPrefixoNumeroSerie() {
        return qVpmnPrefixoNumeroSerie.getQueryValue();
    }
    
    public void setQueryVpmnPrefixoNumeroSerie(String value) {
        this.qVpmnPrefixoNumeroSerie.setQueryValue(value);
    }
    public String getQueryDiametroNominal() {
        return qDiametroNominal.getQueryValue();
    }
    
    public void setQueryDiametroNominal(String value) {
        this.qDiametroNominal.setQueryValue(value);
    }
    public String getQueryComprimento() {
        return qComprimento.getQueryValue();
    }
    
    public void setQueryComprimento(String value) {
        this.qComprimento.setQueryValue(value);
    }
    public String getQueryFatorK() {
        return qFatorK.getQueryValue();
    }
    
    public void setQueryFatorK(String value) {
        this.qFatorK.setQueryValue(value);
    }
    public String getQueryClmhCodigo() {
        return qClmhCodigo.getQueryValue();
    }
    
    public void setQueryClmhCodigo(String value) {
        this.qClmhCodigo.setQueryValue(value);
    }
    public String getQueryClmvCodigo() {
        return qClmvCodigo.getQueryValue();
    }
    
    public void setQueryClmvCodigo(String value) {
        this.qClmvCodigo.setQueryValue(value);
    }
    public String getQueryRzmhCodigo() {
        return qRzmhCodigo.getQueryValue();
    }
    
    public void setQueryRzmhCodigo(String value) {
        this.qRzmhCodigo.setQueryValue(value);
    }
    public String getQueryRzmvCodigo() {
        return qRzmvCodigo.getQueryValue();
    }
    
    public void setQueryRzmvCodigo(String value) {
        this.qRzmvCodigo.setQueryValue(value);
    }
    public String getQueryMarca() {
        return qMarca.getQueryValue();
    }
    
    public void setQueryMarca(String value) {
        this.qMarca.setQueryValue(value);
    }
    // </editor-fold>
    
    
    @Override
    public String getJsServiceFile() {
        return "ui/ztest/cad_modelo_hidrometro.js";
    }
}
